package com.yichenyang.ordersystem.service.impl;

import com.yichenyang.ordersystem.dao.OrdermasterDao;
import com.yichenyang.ordersystem.entity.Ordermaster;
import com.yichenyang.ordersystem.entity.Product;
import com.yichenyang.ordersystem.service.OrdermasterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Ordermaster)表服务实现类
 *
 * @author makejava
 * @since 2020-12-20 16:00:26
 */
@Service
public class OrdermasterServiceImpl implements OrdermasterService {
    @Resource
    private OrdermasterDao ordermasterDao;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public Ordermaster queryById(Integer orderId) {
        return this.ordermasterDao.queryById(orderId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Ordermaster> queryAllByLimit(int offset, int limit) {
        return this.ordermasterDao.queryAllByLimit(offset, limit);
    }

    @Override
    public int queryAll() {
        return ordermasterDao.queryAll();
    }

    /**
     * 新增数据
     *
     * @param ordermaster 实例对象
     * @return 实例对象
     */
    @Override
    public Ordermaster insert(Ordermaster ordermaster) {
        this.ordermasterDao.insert(ordermaster);
        return ordermaster;
    }

    /**
     * 修改数据
     *
     * @param ordermaster 实例对象
     * @return 实例对象
     */
    @Override
    public Ordermaster update(Ordermaster ordermaster) {
        this.ordermasterDao.update(ordermaster);
        return this.queryById(ordermaster.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return this.ordermasterDao.deleteById(orderId) > 0;
    }

    @Override
    public List<Ordermaster> queryByConditions(String payMethod, String sendMethod, String orderId, String start, String end) {
        if (!"".equals(start) || !"".equals(end)) {
            if ("".equals(start) && !"".equals(end)) {
                return ordermasterDao.queryWithEnd(end,payMethod,sendMethod,orderId);
            }
            if ("".equals(end) && !"".equals(start)) {
                return ordermasterDao.queryWithStart(start,payMethod,sendMethod,orderId);
            }
            return ordermasterDao.queryAllConditions(start,end,payMethod,sendMethod,orderId);
        } else {
            return ordermasterDao.queryWithName(payMethod,sendMethod,orderId);
        }
    }

}